package lambda.reduce;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test3
{
	public static void main(String[] args)
	{
		Foo f1 = new Foo("l", 1, 2), f2 = new Foo("l", 1, 2), f3 = new Foo("l", 1, 2);
		Foo f4 = new Foo("c", 1, 2), f5 = new Foo("c", 1, 2);
		Foo f6 = new Foo("q", 11, 22), f7 = new Foo("q", 10, 22);

		Stream<Foo> ss = Stream.of(f1, f2, f3, f4, f5, f6, f7);

		Map<String, List<String>> sumOfSalariesAndBonusesByDept = ss.collect(Collectors.groupingBy(Foo::getName, Collectors.reducing(new ArrayList<String>(), emp -> {
			List<String> ll=new ArrayList<>();
			ll.add(emp.getM()+"");
			ll.add(emp.getN()+"");
			return ll;
		},(a,b)->{
			System.out.println(a);
			System.out.println(b);
			System.out.println("===");
			List<String> ll=new ArrayList<>();
			ll.addAll(a);
			ll.addAll(b);
			return ll;
		})));

		System.out.println(sumOfSalariesAndBonusesByDept);

	}
}

class Foo
{
	// 分组属性
	private String name;

	// 需求：分组平均值
	private Integer m;

	// 需求：分组平均值
	private Integer n;

	public Foo(String name, Integer m, Integer n)
	{
		this.name = name;
		this.m = m;
		this.n = n;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public Integer getM()
	{
		return m;
	}

	public void setM(Integer m)
	{
		this.m = m;
	}

	public Integer getN()
	{
		return n;
	}

	public void setN(Integer n)
	{
		this.n = n;
	}

}
